#ifndef MY_SHAPE_H
#define MY_SHAPE_H

#include <QGraphicsItem>
#include <QPainter>
#include <QColor>

class MyShape : public QGraphicsItem
{
public:
    enum { Type = UserType + 1 };

    MyShape(const QPointF &startPoint, const QColor &color)
        : startPoint_(startPoint), color_(color), isSelected_(false)
    {
        setFlag(QGraphicsItem::ItemIsMovable, false);
        setFlag(QGraphicsItem::ItemIsSelectable, false);
    }

    virtual QPointF getStartPoint() const { return startPoint_; }
    virtual QPointF getEndPoint() const { return startPoint_; }
    virtual void setEndPoint(const QPointF &endPoint) { Q_UNUSED(endPoint); }
    virtual void setRadius(qreal radius) { Q_UNUSED(radius); }

    void setColor(const QColor &newColor) { color_ = newColor; }
    void setSelected(bool selected) { isSelected_ = selected; }
    bool isHighlighted() const { return isHighlighted_; }

    virtual bool isPointNear(const QPointF &point) const = 0;
    virtual void highlightControlPoints(const QPointF &point) = 0;

    int type() const override { return Type; }

protected:
    QPointF startPoint_;
    QColor color_;
    bool isSelected_;
    bool isHighlighted_ = false;
    const qreal hitRadius_ = 8.0;
    const qreal penWidth_ = 2.0;

    // QGraphicsItem interface
public:
    QRectF boundingRect() const override;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
};

#endif // MY_SHAPE_H
